package com.company.JUC.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName SimpleThreadPool
 * @Description TODO
 * @Author ylr
 * @Date 2021/7/22 9:26
 * @Version 1.0
 */
public class SimpleThreadPool {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {

            int finalI = i;
            executorService.execute(()->{
                System.out.println(Thread.currentThread().getName()+" start : " + finalI);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+" end ");

            });
        }
        executorService.shutdown();
        while (!executorService.isTerminated()){

        }
        System.out.println("finished all thread!");
    }
}
